package spring.config;

import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Profile;
import spring.bean.Person;

@Configuration
public class ProfileConfig {

    @Bean
    @Profile("pro")
    public Person proPerson() {
        return new Person("pro涂有");
    }

    @Bean
    @Profile("dev")
    public Person devPerson() {
        return new Person("dev涂有");
    }

    public static void main(String[] args) {

        //不能先指定配置类，因为没有指定profile，在getbean的时候会报bean不存在
//        AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(ProfileConfig.class);
        AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext();
        context.getEnvironment().setActiveProfiles("dev");
        context.register(ProfileConfig.class);
        context.refresh();

        context.getBean(Person.class).tellMyName();

        context.close();
    }
}
